import { addShare } from  "@/api/share/jumpShare";
import { getConfigByKey } from "@/api/system/config";

export async function jumpWaringOrderIdCom(warningOrderId){
    const _this = this;
    let urlShare = "";
  let shareId = "";
    if(warningOrderId){
        let parm = {
      shareAlarm: warningOrderId,
      };
     await addShare(parm).then((res) => {
        if (res.code === 200) {
        shareId = res.data.shareId;
          var arrUrl = location.href.split("//")[0];
        urlShare =
          arrUrl +
          "//" +
          location.href.split("/")[2] +
          "/share/" +
          res.data.shareId;
          }else{
            _this.$message.warning("ak告警获取失败");
          }
    });
    }else{
      _this.$message.warning("ak告警获取失败");
    }
  return { urlShare, shareId };
}

/**
 * 获取APP分享链接
 * @param shareId 短链接
 * @returns copyDoc 链接文本
 */
export async function getAPPShareUrl(shareId) {
  let copyDoc = "";
  const chinatowerUrl = "https://sl.chinatowercom.cn";
  copyDoc = `${chinatowerUrl}/mp/pages/share?ak=${shareId}`;
  const configRes = await getConfigByKey("copyLinkByApp"); //
  // 如果参数配置中存在配置的url，则使用配置中的url，如果不存在，则使用默认的chinatowerUrl
  if (configRes.code === 200 && configRes?.data?.configValue) {
    const url = configRes.data.configValue;
    const shareStr =
      url.substring(url.length - 1, url.length) === "/"
        ? "mp/pages/share?ak="
        : "/mp/pages/share?ak=";
    let copyLinkUrl = configRes.data.configValue + `${shareStr}${shareId}`;
    copyDoc = copyLinkUrl;
  }

  return copyDoc;
  }
